﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Masters/PageOneColumn.master" AutoEventWireup="true" CodeFile="Product.aspx.cs" Inherits="Product" %>

<asp:Content ID="Content1" ContentPlaceHolderID="title" Runat="Server">
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="head" Runat="Server">
    <script type="text/javascript">
        function showFullBookDescription(fullTextIntem) {
            var item = document.getElementById('short-description');
            var textItem = document.getElementById(fullTextIntem);
            if (item != null && item != undefined) {
                if (item.innerText == undefined)
                    item.textContent = textItem.value;
                else
                    item.innerText = textItem.value;
            }
            return false;
        }

        function formsubmit(el) {
            if (!el)
                return false;
            if (el.tagName == 'FORM')
                el.submit();
            else
                return formsubmit(el.parentNode)
            return false;
        }
    </script>
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolderContentClearFix" Runat="Server">

<%
    int id = 0;
    try
    {
        id = int.Parse(Request.QueryString["ID"]);
    }
    catch { }
    
    NhaKinhDoanhDataContext db = new NhaKinhDoanhDataContext();
    
    var query = (from sp in db.TaiLieus
                where sp.ProductID == id
                select sp).Take(1);
    
    if (query.Count<TaiLieu>() == 0)
    {
       
        query = (from sp in db.TaiLieus
                 select sp).Take(1);
    }
   
    Application.Lock();
    Session["CountView"] = int.Parse(Session["CountView"].ToString()) + 1;
    if ((int)Session["CountView"] <= 1 || (int)Session["CountViewID"] != id)
    {
        var queryUpdateView = (from obj in db.TaiLieus
                               where obj.ProductID.Equals(id)
                               select obj).Single();
        queryUpdateView.NumsView++;
        db.SubmitChanges();
        Session["CountViewID"] = id;
    }
   Application.UnLock();
    
    
    TaiLieu tl = query.Single<TaiLieu>();
    
    
         
    List<TaiLieu> lstCDM = (from sp in db.TaiLieus
                           where sp.CatID == tl.CatID
                           orderby sp.DateAdd descending
                           select sp).Take(2).ToList<TaiLieu>();
    List<TaiLieu> lstNB = (from sp in db.TaiLieus
                           where sp.Feature == 1
                           select sp).Take(2).ToList<TaiLieu>();
%>
<!-- Begin: content book-details clearfix -->
<div class="content book-details clearfix">   
    <!-- Begin: book info -->
    <div class="book-info">

		<div class="book-shadow">
			<img width="168" height="178" src="<%= tl.ProductPhotoURL %>" 
                alt="<%= tl.ProductName %>" class="book-detail-img" title="<%= tl.ProductName %>"/>
		</div>
		<div class="book-box">        
			<span onclick="return formsubmit($$('#cartaddform'))" class="start-read link">Thêm vào giỏ hàng</span>            
		</div>		

        <div class="price-device-box clearfix" style="padding-top:10px;">
			            			
			<div class="service-links">
                <form name="cartaddform" id="cartaddform" method="post" action="Cart.aspx">
		            <input type="hidden" id="IID" value="<%= tl.ProductID %>" name="IID"/>
		            <input type="hidden" id="Act" value="1" name="Act"/>
                    <input type="hidden" value="16" id="FID" name="FID"/>
					                    
				    <ul>						
						<li><span onclick="formsubmit(this)" class="buy-it link">Mua sản phẩm này</span></li>
						<li><a href="InviteFriends.aspx?ID=<%=tl.ProductID %>"><b><u>Giới thiệu cho bạn bè</u></b></a></li>		
				    </ul>
                </form>
			</div>            
		</div>

	</div>
    <!-- end: book info -->

    <!-- Begin: floatLeft -->
    <div class="floatLeft">
        <div class="book-info-head">
            <h1><%= tl.ProductName%></h1>
		    <div class="authors"> 
                <a href="Category.aspx?CateID=<%= tl.CatID %>"> <%= tl.DanhMuc.CatName %></a>
            </div>            
        </div>

        <div class="book-info-body">
            <div class="book-description">
                <span class="price"><%= ((double)tl.ProductPrice).ToString() + " USD" %></span><br />
                <span><strong><%=tl.NumsView %></strong> lượt xem</span>  |  <span><strong><%=tl.NumsBuy.ToString()%></strong> lượt mua</span>

			    <hr/>               

            <div id="short-description" class="short-description short-description-collapsed" style="text-align:justify;">
            <% 
                string display = "";
                if (tl.ProductDescription.Length < 500)
                {
                    display = "display:none;";
                }
                   %>
                <div class="more link" style="<%= display %>">&nbsp;... Xem thêm</div>
            
                <span>
                <p>
                    <%= tl.ProductDescription %>
                </p>   
                </span>             
                <span class="less link hidden">Thu gọn</span>
                </div>
               
	        </div>
           
    <div class="more-about-book">
		<div class="more-block clearfix">            
			<div class="more-box">
                <a href="">
				    <h5 class="title">Cùng danh mục</h5>
                </a>
				<ul>

<% 
    for (int i = 0; i < lstCDM.Count; i++)
    {
%>
                    <li class="clearfix">
                        <a href="Product.aspx?ID=<%= lstCDM[i].ProductID %>" class="img">
                        <img alt="<%= lstCDM[i].ProductName %>" 
                        src="<%= lstCDM[i].ProductPhotoURL %>" 
                        class="img-hover-action" title="<%= lstCDM[i].ProductName %>" />
                        </a>
                    
                        <div class="descr">
                            <span class="preview">
                            <a href="Product.aspx?ID=<%= lstCDM[i].ProductID %>"><%= lstCDM[i].ProductName %></a>
                            </span>
                            <%--<span class="author">
                            <a href="">Matthew Reilly</a>
                            </span>
                            <span class="year">2012</span>--%>
                            <span class="price"><%= lstCDM[i].ProductPrice + " USD" %></span>
                            <%--<span class="page-number">320 pages</span>--%>
                        </div>
                    </li>
<% 
    }
%>

				</ul>
			</div>
            
			<div class="more-box ">
					<a class="link" href="">
						<h5 class="title">Nổi bật</h5>             
					</a>
				
				<ul>
                    
<% 
    for (int i = 0; i < lstNB.Count; i++)
    {
%>
                    <li class="clearfix">
                        <a href="Product.aspx?ID=<%= lstNB[i].ProductID %>" class="img">
                        <img alt="<%= lstNB[i].ProductName %>" 
                        src="<%= lstNB[i].ProductPhotoURL %>" 
                        class="img-hover-action" title="<%= lstNB[i].ProductName %>" />
                        </a>
                    
                        <div class="descr">
                            <span class="preview">
                            <a href="Product.aspx?ID=<%= lstNB[i].ProductID %>"><%= lstNB[i].ProductName%></a>
                            </span>
                            <%--<span class="author">
                            <a href="">Matthew Reilly</a>
                            </span>
                            <span class="year">2012</span>--%>
                            <span class="price"><%= lstNB[i].ProductPrice + " USD"%></span>
                            <%--<span class="page-number">320 pages</span>--%>
                        </div>
                    </li>
<% 
    }
%>

                    <%--<li class="clearfix">
                        <a href="" class="img">
                            <img alt="The Girl Who Played with Fire" 
                            onload="return 'http://i4.ebkimg.com/previews/000/000654/000654734/000654734-min-1.jpg'" 
                            class="img-hover-action img-lazy-load" 
                            src="http://i4.ebkimg.com/previews/000/000654/000654734/000654734-min-1.jpg"/>
                        </a>
                        <div class="descr">
                            <span class="preview">
                                <a href="">The Girl Who Played with Fire</a>
                            </span> 
                            <span class="author">
                            <a href="">Stieg Larsson</a>
                            </span>
                            <span class="year">2010</span>
                            <span class="price">US$ 12.49</span>
                            <span class="page-number">608 pages</span>
                        </div>
                    </li>--%>
                </ul>

                <ul class="additional-items">
                    <%--<li class="clearfix">
                        <a href="/783641/private-games/patterson-james/" class="img">
                            <img alt="Private Games" 
                            onload="return 'http://i1.ebkimg.com/previews/000/000783/000783641/000783641-min-1.jpg'" 
                            class="img-hover-action img-lazy-load" 
                            src="http://i1.ebkimg.com/previews/000/000783/000783641/000783641-min-1.jpg"/>
                        </a>
                        <div class="descr">
                            <span class="preview">
                                <a href="/783641/private-games/patterson-james/">Private Games</a>
                            </span> 
                            <span class="author">
                            <a href="">James Patterson</a></span>
                            <span class="year">2012</span>
                            <span class="price">US$ 26.05</span>
                            <span class="page-number">400 pages</span>
                        </div>
                    </li>

                    <li class="clearfix">
                        <a href="/716422/open-season/howard-linda/" class="img">
                            <img alt="Open Season" 
                            onload="return 'http://i2.ebkimg.com/previews/000/000716/000716422/000716422-min-1.jpg'" 
                            class="img-hover-action img-lazy-load" 
                            src="http://i2.ebkimg.com/previews/000/000716/000716422/000716422-min-1.jpg"/>
                        </a>
                        <div class="descr">
                            <span class="preview">
                                <a href="/716422/open-season/howard-linda/">Open Season</a>
                            </span> 
                            <span class="author">
                            <a href="">Linda Howard</a></span>
                            <span class="year">2011</span>
                            <span class="price">US$ 8.99</span>
                            <span class="page-number">368 pages</span>
                        </div>
                    </li>--%>
				</ul>
			</div>            
		</div>        
        
        <script type="text/javascript" language="Javascript">
            var descEl = $$('#short-description');
            if (descEl) {
                descEl.defaultHeight = descEl.offsetHeight;
                descEl.maxHeight = descEl.scrollHeight;
                var timeframe = 300;

                var heightDif = descEl.scrollHeight - descEl.offsetHeight;

                var moreButton = $$('.more', descEl)[0];
                var lessButton = $$('.less', descEl)[0];
                var expandFunc = function () {
                    var timeDiff = new Date().getTime() - descEl.actionStart;
                    if (timeDiff >= timeframe)
                        descEl.style.height = descEl.maxHeight + 'px';
                    else {
                        descEl.style.height = (timeDiff / timeframe) * heightDif + descEl.defaultHeight + 'px';
                        setTimeout(expandFunc, 25);
                    }
                };
                var collapseFunc = function () {
                    var timeDiff = new Date().getTime() - descEl.actionStart;
                    if (timeDiff >= timeframe)
                        descEl.style.height = '';
                    else {
                        descEl.style.height = (timeDiff / timeframe) * (-heightDif) + descEl.maxHeight + 'px';
                        setTimeout(collapseFunc, 25);
                    }
                };
                moreButton.onclick = function () {
                    //descEl.style.height = descEl.maxHeight + 'px';
                    $$.AddClassName(moreButton, 'hidden');
                    $$.RemoveClassName(lessButton, 'hidden');
                    descEl.actionStart = new Date().getTime();
                    expandFunc();
                };
                lessButton.onclick = function () {
                    //descEl.style.height = '';
                    $$.RemoveClassName(moreButton, 'hidden');
                    $$.AddClassName(lessButton, 'hidden');
                    descEl.actionStart = new Date().getTime();
                    collapseFunc();
                };
            }
        </script>
	</div>
                
        </div>
    </div>  <!-- end: floatLeft -->
</div><!-- End: content book-details clearfix -->  
</asp:Content>